/*
 * @lc app=leetcode.cn id=2293 lang=typescript
 *
 * [2293] 极大极小游戏
 */

// @lc code=start
function minMaxGame(nums: number[]): number {
    if (nums.length === 1) return nums[0];
    let isMin = true;
    let arr: number[] = [];
    for (let i = 1; i < nums.length; i += 2) {
        const prev = nums[i - 1];
        const element = nums[i];
        const val = Math[isMin ? "min" : "max"](prev, element);
        arr.push(val);
        isMin = !isMin;
    }
    return minMaxGame(arr);
}
// @lc code=end
